package cate.game.play.skill;

import cate.common.table.d.GDAttr;
import cate.common.table.d.GDFight;
import cate.common.table.d.GDSkill;
import cate.game.attr.FightAttr;
import cate.game.play.base.HpCfg;
import cate.game.play.fighter.Fighter;
import easy.java.dev.note.NoteClass;
import easy.java.dev.note.NoteField;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@NoteClass("技能临时参数")
public class SkillParam {

	@NoteField(value = "指定目标",detail = "特定buff触发的技能需要指定的目标")
	private List<Fighter> appointTargets;

	@NoteField(value = "已经选定过目标",detail = "例如嘲讽 恐惧 也许会找不到目标 但是需要标记一下 不再重选目标")
	private boolean selectTarget;

	@NoteField("施法者临时属性")
	private FightAttr castAttr;

	@NoteField("技能优先选取的目标pid")
	private List<Integer> topPriorityPids;

	@NoteField("增加目标数")
	private int targetNumAdd;

	@NoteField("血量结算配置")
	private List<HpCfg> hpCfgs;

	@NoteField("无视禁活")
	private boolean ignNoRebirth;

	@NoteField("无视控制行动")
	private boolean ignCtrlMove;

	public void reset() {
		appointTargets = null;
		selectTarget = false;
		castAttr = null;
		topPriorityPids = null;
		targetNumAdd = 0;
		hpCfgs = null;
		ignNoRebirth = false;
		ignCtrlMove = false;
	}

	public void readFrom(SkillParam param) {
		appointTargets = param.appointTargets;
		selectTarget = param.selectTarget;
		castAttr = param.castAttr;
		topPriorityPids = param.topPriorityPids;
		targetNumAdd = param.targetNumAdd;
		hpCfgs = param.hpCfgs;
		ignNoRebirth = param.ignNoRebirth;
		ignCtrlMove = param.ignCtrlMove;
	}

	public List<Fighter> getAppointTargets() {
		return appointTargets;
	}

	public void addAppointTarget(Fighter appointTarget) {
		selectTarget = true;
		if (appointTargets == null) {
			appointTargets = new ArrayList<>();
		}
		if (appointTarget == null) {
			return;
		}
		this.appointTargets.add(appointTarget);
	}

	public FightAttr getCastAttr() {
		return castAttr;
	}


	public void addCastAttr(FightAttr attr) {
		if (castAttr == null) {
			castAttr = new FightAttr();
		}
		castAttr.add(attr);
	}

	public void addTopPriorityPid(int targetPid) {
		if (topPriorityPids == null) {
			topPriorityPids = new ArrayList<>();
		}
		topPriorityPids.add(targetPid);
	}

	public List<Integer> getTopPriorityPids() {
		return topPriorityPids;
	}

	public boolean hasSelectTarget() {
		return selectTarget;
	}


	public void addTargetNum(int num){
		this.targetNumAdd+=num;
	}

	public int getTargetNumAdd() {
		return targetNumAdd;
	}

	public void addHpCfgByCoeff(double coeff) {
		if (hpCfgs == null) {
			hpCfgs = new ArrayList<>();
		}
		hpCfgs.add(new HpCfg(GDSkill.Base.CASTER, GDAttr.ATT, coeff));
	}

	public List<HpCfg> getHpCfgs() {return hpCfgs;}

	public void setIgnNoRebirth(boolean ignNoRebirth){
		this.ignNoRebirth = ignNoRebirth;
	}

	public boolean isIgnNoBirth() {
		return ignNoRebirth;
	}

	public void setIgnCtrlMove(boolean ignCtrlMove) {
		this.ignCtrlMove = ignCtrlMove;
	}

	public boolean isIgnCtrlMove() {
		return ignCtrlMove;
	}

	/**
	 * 提前选中的目标已经失效
	 * @return
	 */
	public boolean targetInValid() {
		if (!selectTarget) {
			return false;
		}
		if (appointTargets == null) {
			return false;
		}
		//除了英雄都不应该被选为目标 这里加一个判断防止意外
		appointTargets.removeIf(a -> !GDFight.Fighter.isAreaFighter(a.type));
		//目前追加技能都是针对活着的单位
		appointTargets.removeIf(Fighter::isDead);
		appointTargets.removeIf(f -> f.status.isGhost());
		return appointTargets.isEmpty();
	}
}
